<!-- 编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate?'送货单明细一览':'送货单明细一览'"
    :visible="visible"
    width="860px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @open="init"
    @update:visible="updateVisible">

    <ele-pro-table
      ref="table"

      :datasource="detail"
      :columns="columns"
      :selection.sync="selection"
      :toolbar="false"
      :pageSize="20"
      highlight-current-row
      @row-dblclick="reset"
      height="calc(100vh - 240px)">
      <!-- 表头工具栏 -->
      <template slot="toolbar">
      </template>
      <template slot="cgoldtaxdmcodeid" slot-scope="{row}">
        <a href="#" @click="openEdit(row)">{{row.cgoldtaxdmcodeid}}</a>
      </template>
      <template slot="cartype" slot-scope="{row}" >
        <a href="#"  @click="openTemperature(row)">{{row.cartype}}</a>
      </template>
      <!-- 操作列 -->
      <template slot="usertype" slot-scope="{row}">
        <el-tag
          :type="{'0':'primary', '1':'success','2':'warning'}[row.type.toString()]"
          size="mini">
          {{ {'0':'箱式货车','1':'冷藏车', '2':'保温箱冷藏'}[row.type.toString()] }}
        </el-tag>
      </template>

      <!-- 操作列 -->
    </ele-pro-table>

  </el-dialog>
</template>

<script>
import {mapGetters} from "vuex";
//import elColorPicker from 'el-color-picker'

export default {
  name: 'TransVehicleEdit',
  //components:{elColorPicker},
  computed: {
    ...mapGetters(["permission"]),
  },
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据
      form: Object.assign({}, this.data),
      url: '/transmanage/recordlist',
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'index',
          width: 45,
          align: 'center'
        },
        {
          prop: 'invcode',
          label: '商品编码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'invname',
          label: '通用名称',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center',

        },
        {
          prop: 'cbatchid',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center',

        },
        {
          prop: 'sendGoodsNum',
          label: '送货数量',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center',

        },
        {
          prop: 'rejectGoodsNum',
          label: '拒收数量',
          showOverflowTooltip: true,
          minWidth: 60,
          align: 'center',

        },
        //   {
        //   columnKey: 'action',
        //   label: '操作',
        //   width: 160,
        //   align: 'center',
        //   resizable: false,
        //   slot: 'action',
        //   fixed: "right"
        // }
      ],
      // 表单验证规则
      rules: {
        invcode: [
          {required: true, message: '请输入', trigger: 'blur'}
        ],
        hsl: [
          {required: true, message: '请输入', trigger: 'blur'}
        ],
      },
      invList:[],
      detail:{},
      selection:[],
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
      }
    }
  },
  methods: {
    /*打开窗口是加载明细*/
    init(){
      this.getDetail();
    },
    async getDetail(){
      var res = await this.$http.get('/transmanage/detail?cgoldtaxdmcodeid='+this.form.cgoldtaxdmcodeid+'&page=1&limit=1000');
      //console.log(res);
      if(res.status==200)
      {
        this.detail = res.data.data.records;

      }
    },
    addList(){
      let item={pruchinvoiceid:'',zxspbm:'',scph: ''};
      this.invList.push(item);

    },
    delList(){
      if(this.invList.length==0) return;
      if(this.selection.length==0){
        this.$message.error('请选择一条需要删除的明细');
        return;
      }
      this.invList.splice(this.invList.findIndex((t) => t.zxspbm === this.selection[0].zxspbm && t.scph === this.selection[0].scph), 1);

    },
    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http.post('/transmanage/savecarinfo', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              if (!this.isUpdate) {
                this.form = {};
              }
              this.updateVisible(false);
              this.$emit('done');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
.el-row
{
  margin-bottom: 0px;
}
</style>
